package com.iwuke.dance.wallet.starlight_value;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.iwuke.dance.R;
import com.iwuke.dance.activity.BaseActivity;
import com.iwuke.dance.gadget_view.TitleBarView;
import com.iwuke.dance.http_request.PathUrl;
import com.iwuke.dance.util.ClickableUtil;
import com.iwuke.dance.util.SharedPreferencesUtil;
import com.iwuke.dance.util.Util;
import com.iwuke.dance.util.merchants_connect.NetworkEvent;
import com.iwuke.dance.wallet.balance.WithdrawActivity;
import com.iwuke.dance.wallet.bean.StarlightValueAndBalanceBean;
import com.iwuke.dance.wallet.starlight_value.adapter.StarlightValueDetailsAdapter;
import com.iwuke.dance.wallet.starlight_value.starlight_value_bean.StarlightTransactionRecordHomepageBean;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import androidx.recyclerview.widget.RecyclerView;
import de.greenrobot.event.Subscribe;
import de.greenrobot.event.ThreadMode;

/**
 * @author: 魏从响
 * @date: 2025/9/18
 * 我的星光值
 */
public class MyStarlightValueActivity extends BaseActivity implements View.OnClickListener {

    private TitleBarView title_bar;
    private RecyclerView recycler_view;
    private RelativeLayout rlt_starlight_value_details;
    private String starlightValue="0.0";
    private TextView tv_available_balance;
    private TextView tv_withdraw;
    private ImageView is_show;
    private boolean isShow = true;//true 显示；false 隐藏

    /**
     * @description 网络实时监听
     */
    @Subscribe(threadMode = ThreadMode.MainThread)
    public void onEvent(NetworkEvent networkEvent){
        BaseActivity.setConnect(MyStarlightValueActivity.this,networkEvent,title_bar);

    }

    @Override
    protected int getView() {
        return R.layout.activity_my_starlight_value;
    }

    @Override
    protected void init(View mView) {

        title_bar = findViewById(R.id.title_bar);

        //是否显示余额
        is_show = findViewById(R.id.is_show);
        //可用余额
        tv_available_balance = findViewById(R.id.tv_available_balance);
        //提现
        tv_withdraw = findViewById(R.id.tv_withdraw);



        //列表
        recycler_view = findViewById(R.id.recycler_view);
        rlt_starlight_value_details = findViewById(R.id.rlt_starlight_value_details);


        title_bar.setLeftOnClick(this);
        title_bar.setTitleText("我的星光值");
        title_bar.setLeftColor(R.color.white);
        title_bar.setTitleColor(R.color.white);
        title_bar.setTitleBackgroundColor2(R.drawable.bg_color_97e_5e_shape);
        //是否显示
        is_show.setOnClickListener(this);
        tv_withdraw.setOnClickListener(this);//提现
        rlt_starlight_value_details.setOnClickListener(this);

    }

    @Override
    protected void initData() {

        starlightValue = getIntent().getStringExtra("text");
        tv_available_balance.setText(starlightValue);//可用余额

        starlightTransactionRecordHomepage();

    }

    /**
     * @description 获取星光值交易交易记录(首页)
     * @param
     * @return
     * @author 魏从响
     * @time 2025/9/20 14:49
     */
    private void starlightTransactionRecordHomepage() {

        Map<String, String> map = new HashMap<>();
        map.put("walletId",SharedPreferencesUtil.getInstance().getWalletId());//钱包id
        PathUrl.starlightTransactionRecordHomepage(map, new PathUrl.DataCallBackList<StarlightTransactionRecordHomepageBean>() {
            @Override
            public void onSucessList(List<StarlightTransactionRecordHomepageBean> list) {
                setLinearLayoutManager(MyStarlightValueActivity.this,recycler_view);
                StarlightValueDetailsAdapter detailsAdapter = new StarlightValueDetailsAdapter(MyStarlightValueActivity.this, R.layout.adapter_starlight_value_details, list);
                recycler_view.setAdapter(detailsAdapter);

            }

            @Override
            public void onFail(String errorCode) {

            }
        });

    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.img_left){//返回
            finish();
        }else if (v.getId() == R.id.is_show) {
            //钱/金额是否显示
            if (isShow) {
                isShow = false;
                is_show.setImageResource(R.mipmap.img_hide);//闭眼
                tv_available_balance.setText("****");
            }else {
                isShow = true;
                is_show.setImageResource(R.mipmap.img_show);//睁眼
                tv_available_balance.setText(starlightValue);
            }

        }else if(v.getId()==R.id.tv_withdraw){//提现
            new ClickableUtil().isClickable(tv_withdraw);
            StarlightValueAndBalanceBean bean = new StarlightValueAndBalanceBean();
            bean.type = 2;
            bean.starlightValue = starlightValue;
            Bundle bundle = new Bundle();
            bundle.putSerializable("data", bean);
            Util.setIntent(MyStarlightValueActivity.this, WithdrawActivity.class,bundle);

        }else if (v.getId()==R.id.rlt_starlight_value_details){//星光值明细
            Util.setIntent(MyStarlightValueActivity.this,StarlightValueDetailsActivity.class,starlightValue);
        }
    }

}
